{% extends "shared/_layout.html" %} 

{% block title %}
<title>{{ title }}</title>
{% endblock %} 

{% block htmlHead %} 
{% endblock %} 

{% block contentBody %}
 <div class="container body-content">

<h2 class="page-header">
    Article
</h2>

<div class="row">
  <div class="col-md-2">
    {% include "admin/shared/_menu.html" %}
  </div>
  <div class="col-md-10">
     <div class="panel panel-default">
       <div class="panel-heading">
         <a onclick="fnAdd()"><i class="glyphicon glyphicon-plus"></i>添加</a>
       </div>
        <table class="table table-bordered">
        <tr>
            <th>
                Title
            </th>
            <th>
                Intro
            </th>
            <th>
                PicUrl
            </th>
            <th>
                CategoryID
            </th>
            <th>
                Content
            </th>
            <th>
                Creater
            </th>
            <th>
                Updater
            </th>
            <th>
                CreateDate
            </th>
            <th>
                UpdateDate
            </th>
            <th>
               操作
            </th>
        </tr>
        {% for item in pageList.items %}
        <tr>
            <td>
                {{item.title}}
            </td>
            <td>
                {{item.intro}}
            </td>
            <td>
                {{item.pic_url}}
            </td>
            <td>
                {{item.category_id}}
            </td>
            <td>
                {{item.content}}
            </td>
            <td>
                {{item.creater}}
            </td>
            <td>
                {{item.updater}}
            </td>
            <td>
                {{ moment(item.create_date).format("YYYY-MM-DD") }}
            </td>
            <td>
                {{ moment(item.update_date).format("YYYY-MM-DD") }}
            </td>
            <td>
                <a onclick="fnEdit({{item.id}})" class="text-primary">修改</a>
                <a onclick="fnDel({{item.id}})" class="text-danger">删除</a>
            </td>
        </tr>
        {% endfor %}
      </table>
      <div class="panel-footer">
      {% include "shared/_pager.html" %} 
      </div>
    </div>
  </div>
</div>
<div id="formModal" class="modal fade " tabindex="1" role="dialog">
  <div class="modal-dialog " role="document">
    <div class="modal-content">
    </div>
  </div>
</div>
<div style="display: none;">
  <iframe name="frame_save"></iframe>
</div>
{% endblock %} 
    
{% block htmlScript %} 
<script type="application/javascript">
  function fnDel(id){
    if(!confirm("确定要删除吗？")){
      return false;
    }
    var url = "/admin/article/delete/"+ encodeURI(id) +"?tmp="+ (new Date()).getTime();
    $.ajax({
      type : "POST",
      url : url,
      success : function(res) {
        if(res && res.code == 200 ){
          window.location.reload();
        }else{
          alert(res.msg);
        }
      },
      error : function(e){
      alert("发生错误，删除失败！");
      }
    });
  }

  function fnAdd() {
    var url = "/admin/article/add?tmp="+ (new Date()).getTime();
    $('#formModal .modal-content').empty();
    $("#formModal .modal-content").load(url, function() {
      $('#formModal').modal({
        show:true,
        keyboard:true,
        backdrop:'static'
      }); 
    });
  }

  function fnEdit(id) {
    var url = "/admin/article/edit/"+encodeURI(id)+"?tmp="+ (new Date()).getTime();
    $('#formModal .modal-content').empty();
    $("#formModal .modal-content").load(url, function() {
    $('#formModal').modal({
      show:true,
      keyboard:true,
      backdrop:'static'
    });
    });
  }

  function fnCancel() {
    $('#formModal').modal('hide');
  }

  function fnOnSaved() {
    window.location.reload();
    $('#formModal').modal('hide');
  }
</script>
{% endblock %}